﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace test2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        double temp1;
        double temp2;
        short pos = 0;
        string temp1_string = "";
        string temp2_string = "";

        public void add_sign(string  sign)//显示textbox上的字符
        {
            textBox1.Text = textBox1.Text + sign;
            if(pos==0)
            {
                temp1_string = temp1_string + sign;//first number
            }
            if(pos!=0)
            {
                temp2_string = temp2_string + sign;//second number。由于中间隔着运算符
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        private void button11_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "+";
            pos = (short)'+';
        }

        private void button1_Click(object sender, EventArgs e)
        {
            add_sign("1");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            add_sign("2");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            add_sign("3");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            add_sign("4");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            add_sign("5");
        }

        private void button6_Click(object sender, EventArgs e)
        {
            add_sign("6");
        }

        private void button7_Click(object sender, EventArgs e)
        {
            add_sign("7");
        }

        private void button8_Click(object sender, EventArgs e)
        {
            add_sign("8");
        }

        private void button9_Click(object sender, EventArgs e)
        {
            add_sign("9");
        }

        private void button10_Click(object sender, EventArgs e)
        {
            add_sign("0");
        }

        private void button12_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "-";
            pos = (short)'-';
        }

        private void button13_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "*";
            pos = (short)'*';
        }

        private void button14_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "/";
            pos = (short)'/';
        }

        private void button16_Click(object sender, EventArgs e)//AC,operation
        {
            textBox1.Text = "";
            temp1 = 0;
            temp2 = 0;
            pos = 0;
            temp1_string="";
            temp2_string="";
        }

        private void button15_Click(object sender, EventArgs e)// =操作
        {
            textBox1.Text = textBox1.Text + "=";

            temp1 = Convert.ToDouble(temp1_string);//转为double类型进行计算
            temp2 = Convert.ToDouble(temp2_string);

            switch(pos)
            {
                case (short)'+':
                    textBox1.Text = textBox1.Text + (temp1 + temp2).ToString();
                    break;
                case (short)'-':
                    textBox1.Text = textBox1.Text + (temp1 - temp2).ToString();
                    break;
                case (short)'*':
                    textBox1.Text = textBox1.Text + (temp1 * temp2).ToString();
                    break;
                case (short)'/':
                    textBox1.Text = textBox1.Text + (temp1 / temp2).ToString();
                    break;
                case (short)'%':
                    textBox1.Text = textBox1.Text + (temp1 % temp2).ToString();
                    break;
                dafault:
                    break;
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button17_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "%";
            pos = (short)'%';
        }
    }
}
